<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>05_版心与居中测试</title>
</head>
<style>
<!--    去除所有元素自带的内外间距-->
    *{
        margin: 0;
        padding: 0;
    }
    .main{
        background-color: yellow;
    }
    .center {
        width: 500px; /*设置宽度且居中*/
        margin: 0 auto;
        background-color: red;
    }

    .card{
        width: 300px;
        height: 300px;
        background-color: blue;
        margin: 0 auto;
        text-align: center;
        line-height: 300px;
    }
</style>
<body>

<div class="main">
    <div class="center">
        <div class="card">我是内容</div>
        <div class="card">我是内容</div>
        <div class="card">我是内容</div>
        <div class="card">我是内容</div>
    </div>
</div>

</body>
</html>